<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<?php
/**
 * Created by PhpStorm.
 * User: dapeng
 * Date: 2019-12-06
 * Time: 15:41
 */


//-----------------------写入账户--------------------------
$user = "zhangsan";
$pass = "123456";
$obj = array("user"=>$user,"pass"=>$pass);
$users = [];
array_push($users,$obj);

//将数组转为JSON数据
$json = json_encode($users);



file_put_contents("user.json",$json);


//-----------------------读取账户--------------------------
$users = file_get_contents("user.json");
//将JSON数据转为数组
$users = json_decode($users);
//var_dump($users);


//-----------------------再次写入一个用户--------------------------
$user = "lisi";
$pass = "123456";
$obj = array("user"=>$user,"pass"=>$pass);

array_push($users,$obj);
$json = json_encode($users);
file_put_contents("user.json",$json);

